//
//  WaitForInterviewTableViewCell.m
//  CYWFrame
//
//  Created by 于顺燊 on 2018/9/26.
//  Copyright © 2018年 Macx. All rights reserved.
//

#import "WaitForInterviewTableViewCell.h"

@implementation WaitForInterviewTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
	self.joinRoomBtn.layer.cornerRadius = 12;
	self.joinRoomBtn.backgroundColor = UIMainColorRGB;
    // Initialization code
}

- (void)setModel:(InterviewManageModel *)model
{
	if (_model != model) {
		_model = model;
		if (self.type == 0) {
			[self.leftImg sd_setImageWithURL:[NSURL URLWithString:model.company_logo] placeholderImage:IMAGE(@"placeHolder")];
			self.leftTitle.text = model.company_title;
			[self.rightImg sd_setImageWithURL:[NSURL URLWithString:model.head_img] placeholderImage:IMAGE(@"placeHolder")];
			self.rightTitle.text = model.name;
			
		}
		else
		{
			[self.leftImg sd_setImageWithURL:[NSURL URLWithString:model.head_img] placeholderImage:IMAGE(@"placeHolder")];
			self.leftTitle.text = model.name;
			[self.rightImg sd_setImageWithURL:[NSURL URLWithString:model.company_logo] placeholderImage:IMAGE(@"placeHolder")];
			self.rightTitle.text = model.company_title;
		}
		self.interviewDate.text = [self changeTimeStamptoString:model.interview_time];
		self.position.text = model.category_title;
	}
}
- (NSString *)changeTimeStamptoString:(NSString *)timeStampString {
	
	// iOS 生成的时间戳是10位
	NSTimeInterval interval = [timeStampString doubleValue];
	
	if (interval == 0) {
		return @"";
	}
	NSDate *date = [NSDate dateWithTimeIntervalSince1970:interval];
	NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
	[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
	NSString *dateString = [formatter stringFromDate: date];
	NSLog(@"服务器返回的时间戳对应的时间是:%@",dateString);
	
	return dateString;
}

- (void)joinRoom:(UIButton *)sender
{
	[self.delegate joinRoom:self.model.chatroom_id time:self.model.interview_time interviewId:self.model.interview_id resumeId:self.model.resume_id positionId:self.model.position_id];
}

- (void)setFrame:(CGRect)frame
{
	frame.origin.y += 10;
	
	frame.size.height -= 10;
	
	[super setFrame:frame];
}

- (void)setMode:(NSInteger)mode
{
	if (_mode != mode) {
		_mode = mode;
	}
	if (mode == 0) {
		[self.joinRoomBtn addTarget:self action:@selector(joinRoom:) forControlEvents:UIControlEventTouchUpInside];
	}
	else
	{
		[self.joinRoomBtn setTitle:@"面试回放" forState:UIControlStateNormal];
	}
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
